import {
  getPageData,
  findByOrgIdAndUploadYear,
  changStatus
} from '@/services/gastroscopestatisticsApi';

export default {
  namespace: 'gastroscopestatistics',

  state: {
    // 列表数据
    data: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *getPageData({ payload }, { call, put }) {
      const response = yield call(getPageData, payload);
      yield put({
        type: 'cb4getPageData',
        payload: response,
      });
    },

    /**
     * 点击查看按钮
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *findByOrgIdAndUploadYear({ payload }, { call, put }) {
      const response = yield call(findByOrgIdAndUploadYear, payload);
      return response;
    },

    /**
     * 改变状态
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *changStatus({ payload }, { call, put }) {
      const response = yield call(changStatus, payload);
      return response;
    },
  },

  reducers: {
    cb4getPageData(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
